<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ContainsAlphanumbericValidator
 *
 * @author bien.tran
 */

namespace Blog\BlogBundle\Validator\Constraints;

use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class ContainsAlphanumbericValidator extends ConstraintValidator{
    
    public function isValid($value, Constraint $constraint) {
        
        if (!preg_match('/^[a-zA-Za0-9]+$/', $value, $matches)) {
            //$this->context->addViolation($constraint->message, array('%string%' => $value), $value);
            $this->setMessage($constraint->message, array('%string%' => $value));
            return false;
        }
        return true;
    }
}

?>
